package com.zut.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.zut.oss.adapter.StorageAdapter;
import com.zut.oss.adapter.AliyunOssAdapterImpl;
import com.zut.oss.adapter.MinioOssAdapterImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.service.type}")
    private  String storageType;

    //在创建storageServiceBean的时候判断是哪一个实现类
    //直接注入配置文件指定的实现类
    @Bean
    @RefreshScope
    public StorageAdapter storageAdapter(){
        if (storageType.equals("minio")){
            return new MinioOssAdapterImpl();
        }else if (storageType.equals("aliyun"))
            return new AliyunOssAdapterImpl();
        else
            throw new IllegalArgumentException("未找到合法的文件批处理方式！");
        
    }

}
